package aole.mindfx.model;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;

public class MindFXCallThis extends MindFXCall {
	
	public MindFXCallThis( String n, MindFXMethod p ) {
		super( n,p );
	}

	public String toString() {
		return method.getName()+"()";
	}

	@Override
	public boolean setXMLAttribute( String att, String value ) {
		if( super.setXMLAttribute( att, value ) ) return true;

		switch( att ) {
		case "method":
			setMethod( parent.getFXClass().getMethod( value ) );
			return true;
		}
		return false;
	}

	@Override
	public void saveXML( Document doc, Element e ) {
		e.setAttribute( "method", method.getName() );
	}

	@Override
	public void loadXML( org.w3c.dom.Node node ) {
		// get attributes
		NamedNodeMap atts = node.getAttributes();
		for( int i = 0; i < atts.getLength(); i++ ) {
			org.w3c.dom.Node att = atts.item( i );
			if( att.getNodeType() == org.w3c.dom.Node.ATTRIBUTE_NODE ) {
				if( !setXMLAttribute( att.getNodeName(), att.getNodeValue() ) )
					System.out.println( "Attribute not found: "
							+ att.getNodeName() + "=" + att.getNodeValue()
							+ "@" + getName() );
			}
		}
	}

}
